#include <stdio.h>

#define MAX_N	20
#define MAX_K	20
#define MAX_F	20000
#define INF 	10000

int a[MAX_K] = {0, 1, 8, 13}; 
int n=7, k=3; 

int f[MAX_F]; 

int max_c; 
int ar[MAX_K]; 

int min(int a, int b)
{
	return a<b?a:b;
}

void check_result(void)
{
	int i, c=1, p; 
	f[0] = 0; 
	while (1) {
		f[c] = INF; 
		for (i=0; i<=k; i++) {
			p = c-a[i]; 
			printf("c=%d, p=%d, i=%d, a[i]=%d, f[c]=%d, f[p]=%d\n", c, p, i, a[i], f[c], p>=0?f[p]:-1); 
			if (p<0) 
				continue; 
			f[c] = min(f[c], f[p]+1); 
		}
		if (f[c]>n) 
			break; 
		printf("  --> f[%d]=%d\n", c, f[c]); 
		c++;
	}
	printf("\n"); 
	for (i=0; i<=k; i++) {
		printf("%d ", a[i]); 
	}
	printf("f[%d]=%d\n", c, f[c]); 
	
	if (c-1>max_c) {
		max_c = c-1; 
		for (i=0; i<=k; i++) {
			ar[i] = a[i]; 
		}
	}
}

int main()
{
	check_result(); 
	return 0; 
}

